package jdbc;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import javax.sql.DataSource;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

/*
* 数据库连接
* */
public class JdbcUtilByDruid {
    private static DataSource ds;
    static {
        try {    Properties properties = new Properties();

        properties.load(new FileInputStream("src\\resource\\druid.properties"));

            ds= DruidDataSourceFactory.createDataSource(properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static Connection getConnection() throws SQLException {
        return ds.getConnection();
    }
    public static void getClose(ResultSet set, Statement statement, Connection connection){
        try {
            if (set!=null)set.close();
            if (statement!=null)statement.close();
            if (connection!=null)connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
